package com.gandong8.hbase.web.handler;

import com.gandong8.hbase.web.exception.LoginException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = NoHandlerFoundException.class)
    public Object notFoundHandler() {
        return "redirect:/404";
    }


    @ExceptionHandler(value = LoginException.class)
    public String notLoginHandler() throws Exception {
        return "redirect:/login";
    }

    @ExceptionHandler(value = Exception.class)
    public Object errorHandler(Exception e) throws Exception {
        e.printStackTrace();
        return "redirect:/err";
    }









}
